'use strict'

import axios from 'axios'

const baseURL = process.env.NODE_ENV === 'production' ? "http://data.e-fts.cn/api/" : '/api';
axios.defaults.baseURL = baseURL

axios.interceptors.request.use(config => {
  let token = sessionStorage.getItem("token")
  if (token) {
    config.headers = {
      'token': token,
    };
  }
  return config
}, error => {
  Promise.reject(error)
})

axios.interceptors.response.use(response => {
  return response
}, error => {
  return Promise.resolve(error.response)
})
export default {
  post(url, data) {
    return axios({
      method: 'post',
      url,
      data,
      responseType: 'blob',
      timeout: 10000,
      headers: {
        'Content-Type': 'application/json'
      }
      
    }).then(
      (response) => {
        return response
      }
    )
  },
  get(url, params) {
    return axios({
      method: 'get',
      url,
      params, // get 请求时带的参数
      timeout: 10000,
      responseType: 'blob',
      headers: {
        'X-Requested-With': 'XMLHttpRequest'
      }
    }).then(
      (response) => {
        return response
      }
    )
  }
}
